package tul.cot.io;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

public class PlotPoint implements Writable {

	private Header header = new Header();
	private double value;
	
	public PlotPoint() {}
	
	public PlotPoint(Header header, double value) {
		set(header, value);
	}
	
	public void set (Header header, double value) {
		this.header = header;
		this.value = value;
	}
	
	@Override
	public boolean equals(Object o) {
		PlotPoint other = (PlotPoint) o;
		return this.header.equals(other.header) && this.value == other.value;
	}
	
	@Override
	public void readFields(DataInput in) throws IOException {
		header.readFields(in);
		value = in.readDouble();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		header.write(out);
		out.writeDouble(value);
	}
	
	public String getLabel() {
		return header.getLabel();
	}
	
	public int getSegment() {
		return header.getSegment();
	}
	
	public double getValue() {
		return value;
	}
	
	@Override
	public String toString() {
		return String.format("(%s, %s)", header.toString(), Double.toString(value));
	}

}
